﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.SessionState;
using Config.Enum;
using HighLowTriple7;
using PaymentBLL;
using WebTriple7.Class;

namespace WebTriple7.Handler
{
    /// <summary>
    /// Summary description for AccountHandler
    /// </summary>
    public class AccountHandler : IHttpHandler, IReadOnlySessionState
    {

        public void ProcessRequest(HttpContext context)
        {
            var t = context.Request.QueryString["t"] ?? "";
            switch (t)
            {
                case "GetAssets":
                    GetAssets(context);
                    break;
                case "GetHelp":
                    GetHelp(context);
                    break;  
            }            
        }
        private void GetAssets(HttpContext context)
        {
            var ctr = new CtrAccount();
            var info = ctr.SelectAccountInfo(Utils.UserUtils.AccountId);
            var gateWayId = Convert.ToInt32(context.Request.QueryString["gateWayId"] ?? "0");
            var gateWay = new GateWayPayment((GateWay)gateWayId);
            var blance = gateWay.GetBlance().Data;
            var obj = new
                          {
                              info.Au,
                              info.Ag,
                              Blance = blance
                          };
            context.Response.ContentType = "application/json";
            context.Response.Write(Newtonsoft.Json.JsonConvert.SerializeObject(obj));
        }
        private void GetHelp(HttpContext context)
        {
            var type = Convert.ToInt32(context.Request.QueryString["type"] ?? "0");
            var lst = Triple7.GetHelpInfoList(type);           
            context.Response.ContentType = "application/json";
            context.Response.Write(Newtonsoft.Json.JsonConvert.SerializeObject(lst));
        }  
        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}